Apply the manifest.
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/deploy.yaml
(optional) Make the controller load balanced. Edit the manifest & change spec.type: LoadBalancer
.
$ kubectl edit svc ingress-nginx-controller -n ingress-nginx
this can be checked by verifying the service is load balanced at the correct IP with:
$ kubectl get all -n ingress-nginx
Create an ingress rule, ingress.yaml
.
The following rule will redirect a call to the controller's load balancing IP:80 to
service_name
:service_port
.
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: <name>
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
serviceName: <service_name>
servicePort: <service_port>
where service_name
can be retrieved from the output of kubectl get svc -n <namespace>
.
To accept other inbound ports at the load balancer, it is necessary to add to spec.ports
listed in controller's manifest.
Apply the ingress rule.
$ kubectl apply -f ingress.yaml -n <namespace>
Assuming that ingress-nginx
has been deployed and the tcp service to be ingressed is running with service_name
on port service_port
:
Create a new configMap in namespace, namespace
.
$ vi new-configmap.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: <namespace>
data:
<service_port>: "<namespace>/<service_name>:<service_port>"
Edit the ingress controller service.
$ kubectl edit svc ingress-nginx-controller -n ingress-nginx
and add a new entry under spec:ports:
:
- name: <name>
port: <service_port>
protocol: TCP
targetPort: <service_port>
where name
is arbitrary.
Edit the deployment to allow tcp services.
$ kubectl edit deployment ingress-nginx-controller -n ingress-nginx
adding the --tcp-services
flag under spec:template:spec:containers:args
pointing to the configMap (with namespace):
- args:
- /nginx-ingress-controller
.
.
- --tcp-services-configmap=<namespace>/tcp-services